package com.caowei.weicimpress.weicimpress.widget;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.caowei.weicimpress.weicimpress.R;


/**
 * Created by caoweiPc on 2014/7/21.
 */
public class Toast {
    public static final int  LENGTH_SHORT=android.widget.Toast.LENGTH_SHORT;
    public static final int LENGTH_LONG =android.widget.Toast.LENGTH_LONG;
    private  int duration;
    private  View view;
    private  android.widget.Toast toast;
    private static Handler handler = new Handler(Looper.getMainLooper());
    private  Toast(){
    }
    public static Toast makeText(Context context, CharSequence text, final int duration) {
        Toast myToast=new Toast();
        myToast.view= LayoutInflater.from(context).inflate(R.layout.toast,null);
        TextView textView= (TextView) myToast.view.findViewById(R.id.text);
        textView.setText(text);
        myToast.duration=duration;
        android.widget.Toast toast1=new android.widget.Toast(context);
        myToast.toast=toast1;
        return myToast;
    }

    public void show(){
        new Thread(){
            @Override
            public void run() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        toast.setView(view);
                        toast.setDuration(duration);
                        toast.show();
                    }
                });
            }
        }.start();
    }
}
